﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Fluq
{
	sealed class DependencyKeyComparer : IComparer<IDependencyKey>
	{
		public int Compare(IDependencyKey x, IDependencyKey y)
		{
			int difference = String.Compare(x.Type.FullName, y.Type.FullName, StringComparison.OrdinalIgnoreCase);

			if (difference == 0)
			{
				IComparable xid = x.Id;
				IComparable yid = y.Id;

				if (xid == null)
				{
					return yid == null ? 0 : 1;
				}
				else
				{
					return xid == null ? -1 : xid.CompareTo(yid);
				}
			}

			return difference;
		}
	}
}
